package com.abc.controller;

import com.abc.entity.User;
import com.abc.service.UserService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
@Slf4j
public class UserController {
    @Autowired
    UserService userService;
    @PostMapping("/login")
    public User login(User user){
        log.info("获取到的参数是  {}" ,user);
        LambdaQueryWrapper<User> queryWrapper1 = new LambdaQueryWrapper<>();
        queryWrapper1.eq(user.getUsername() != null,User::getUsername,user.getUsername());
        User user1 = userService.getOne(queryWrapper1);
        if(user1 != null){
            if(user1.getPassword().equals(user.getPassword()) && user1.getFlag() == user.getFlag()){
                //登陆成功
                log.info("登陆成功");
            }else{
                //密码或者身份错误
                log.error("密码或者身份错误");
            }
        }else{
            //用户名错误
            log.error("用户名错误");
        }
        return user;
    }
}
